#ifndef DROPMANAGER_H
#define DROPMANAGER_H

#include <QObject>
#include <QMap>

class DroppableWidget;
class PagesWidget;
class DragableTab;
class QDropEvent;
class WidgetTree;

/*
    继承了 QObject 的单例类
    整体功能:
        作为整体拖拽的管理类，通过Qt中的EventFilter实现对注册组件的拖拽
    相关功能
        1、获取单例类
        2、添加或移除droppableWidget到manager，确保拖拽释放时可以搜索到该组件及所管理的tab
        3、查找所属编号的pagesWidget或者单独的page
        4、组件实现installEventFilter后，dropManager自动完成拖拽释放
*/

class DropManager : public QObject
{
    Q_OBJECT
public:
    static DropManager* GetInstance();
    static void SetParent(QObject* parent);

    void AddDroppableWidget(DroppableWidget* widget);
    void RemoveDroppableWidget(DroppableWidget* widget);
    std::pair<DragableTab*, QWidget*> FindSinglePage(int widgetId, int pagesWidgetId, int tabId) const;
    PagesWidget* FindPagesWidget(int widgetId, int pagesWidgetId) const;

protected:
    bool eventFilter(QObject *watched, QEvent *event) override;

private:
    DropManager(QObject* parent = nullptr);
    DropManager(const DropManager&) = delete;
    DropManager& operator=(const DropManager&) = delete;

    static bool FilterSinglePageDrop(QObject *watched, QDropEvent *dropEvent, const std::tuple<int, int, int>& dragIndex);
    bool FilterPagesDrop(QObject *watched, QDropEvent *dropEvent, const std::pair<int, int>& dragIndex);



    QMap<int, DroppableWidget*> mWidgets;
};

#endif // DROPMANAGER_H
